//
//  AppDelegate.m
//  QuickCure
//
//  Created by 徐绩 on 16/5/4.
//  Copyright © 2016年 ayumi. All rights reserved.
//

#import "AppDelegate.h"
#import "AYMLeftController.h"
#import "AYMHomeController.h"
#define kAppKey @"12768467bd48d"
#define kAPPSecret @"2529f6fe474856d133803488c6e4d134"
#import "UMSocial.h"
#import "UMSocialSinaSSOHandler.h"
#import "AYMForceTouchClik.h"
@interface AppDelegate ()

@property (nonatomic,strong) JASidePanelController * viewController;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
   
    self.viewController = [[JASidePanelController alloc]init];
    self.viewController.shouldDelegateAutorotateToVisiblePanel = NO;
    
    self.viewController.leftPanel = [[AYMLeftController alloc]init];
    self.viewController.centerPanel = [[UINavigationController alloc]initWithRootViewController:[[AYMHomeController alloc]init]];
    
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    [self setupNavigationBarStyle];
    
    
    //初始化应用，appKey和appSecret从后台申请得
    [SMSSDK registerApp:kAppKey withSecret:kAPPSecret];
    
    
    
    //分享微博
    [self UMShare];
    //判断是否支持3dtouch
    if (self.viewController.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
        //调用增加3dtouch功能
        [AYMForceTouchClik loginForceTouch];
    }
    
    return YES;
}

//实现3dtouch的代理方法
-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{
    if ([shortcutItem.type isEqualToString:@"user"]) {
        //方法实现
    }else if ([shortcutItem.type isEqualToString:@"sugge"]){
        //方法实现2
    }else if ([shortcutItem.type isEqualToString:@"login"]){
        //方法实现3
    }
    
}
#pragma mark - 友盟分享
- (void)UMShare {
    
    [UMSocialData setAppKey:@"572e217f67e58e4a47003a7d"];
    
    //分享微博
    [UMSocialSinaSSOHandler openNewSinaSSOWithAppKey:@"2248209688"
                                              secret:@"8bfecb608f56f31bd8ec1d7427e7d5ab"
                                         RedirectURL:@"http://sns.whalecloud.com/sina2/callback"];
}

#pragma mark - 分享的系统回调
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    BOOL result = [UMSocialSnsService handleOpenURL:url];
    if (result == false) {
        //调用其他SDK，例如支付宝SDK等
        NSLog(@"失败了");
    }
    return result;
}

#pragma mark - 统一设置导航栏样式
-(void)setupNavigationBarStyle{

    UINavigationBar *navBar = [UINavigationBar appearance];
    [navBar setBackgroundImage:[UIImage imageNamed:@"nav"] forBarMetrics:UIBarMetricsDefault];
    
    NSDictionary *dict = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
    [navBar setTitleTextAttributes:dict];
    
    [navBar setTintColor:[UIColor whiteColor]];
    
}

# pragma mark -
# pragma mark 实现3Dtouch


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    [AYMSQLiteManager clearCache];
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
